package cn.suimg.neo4j.repository;

import cn.suimg.neo4j.graph.AlbumGraph;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface AlbumGraphRepository extends Neo4jRepository<AlbumGraph, Long> {

    AlbumGraph findByAlbumId(@Param("albumId") Integer albumId);

    @Query(value = "match (singer:歌手) -[:发布] -> (albumGraph:专辑) where singer.singerId = {singerId} return albumGraph",
            countQuery = "match (singer:歌手) -[:发布] -> (albumGraph:专辑) where singer.singerId = {singerId} return count(albumGraph)")
    Page<AlbumGraph> getBySingerId(@Param("singerId") Integer singerId, Pageable page);


    @Query("match (singer:歌手) -[:发布] -> (albumGraph:专辑) where singer.singerId = {singerId} return albumGraph")
    List<AlbumGraph> findBySingerId(@Param("singerId") Integer singerId);

}
